package com.ww.springboot.boot.algorithm.leetcode1;

/**
 * todo
 *
 * @author wanwei
 * @since 2022-03-16 09:28
 */
public class AR75颜色分类 {

    public static void main(String[] args) {

        int[] nums = {2, 0, 2, 1, 1, 0};
        sortColors(nums);
        PrintUtil.print(nums);
    }

    public static void sortColors(int[] nums) {
        int size0 = 0;
        int size1 = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                size0++;
            } else if (nums[i] == 1) {
                size1++;
            }
        }

        for (int i = 0; i < nums.length; i++) {
            if (i < size0) {
                nums[i] = 0;
            } else if (i < size0 + size1) {
                nums[i] = 1;
            }else {
                nums[i] = 2;
            }
        }
    }
}
